import { Button } from "antd"
import React from "react"
class PureCom extends React.PureComponent {
  constructor(props) {
    super(props)
    this.state = {
      data: {
        age: 28
      }
    }
  }
  chageStateAge = () => {
    const { data } = this.state
    data.age++
    this.setState({ data: { ...data } })
  }

  changeFatherName = () => {
    let { setName } = this.props
    let random = Math.random()
    setName("小毅" + random)
  }

  render() {
    const { data } = this.state
    const { name } = this.props
    console.log("Purerender");
    return <div className="box" >
      <div className="show" >
        <div> 父组件prop传递的姓名: {name} </div>
        <div> 子组件 state年龄:{data.age}</div>
        <Button type="primary" onClick={this.chageStateAge} >PureComponent age++</Button>
        <Button type="primary" onClick={this.changeFatherName} >修改父组件的 名字</Button>
      </div>
    </div>
  }
}
export default PureCom